package cn.ffcs.uec.recordsApproval.component;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import lombok.Getter;
import lombok.Setter;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Div;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;

import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.outStaff.manager.UecOutStaffManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.recordsApproval.component.bean.RecordsApprovalListBoxExtBean;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.manager.ActRunTaskManager;
import cn.ffcs.uec.recordsApproval.manager.AtiUserManager;
import cn.ffcs.uec.recordsApproval.model.AtiUser;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.recordsApproval.vo.TaskVo;
import cn.ffcs.uec.staff.manager.UecAssManager;
import cn.ffcs.uec.staff.manager.UecDocEduManager;
import cn.ffcs.uec.staff.manager.UecEncManager;
import cn.ffcs.uec.staff.manager.UecFamilyManager;
import cn.ffcs.uec.staff.manager.UecNationdutyManager;
import cn.ffcs.uec.staff.manager.UecPartyLogManager;
import cn.ffcs.uec.staff.manager.UecPsndocWadocManager;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.manager.UecPunishManager;
import cn.ffcs.uec.staff.manager.UecTalentTeamManager;
import cn.ffcs.uec.staff.manager.UecTitleManager;
import cn.ffcs.uec.staff.manager.UecTrialManager;
import cn.ffcs.uec.staff.model.UecAss;
import cn.ffcs.uec.staff.model.UecDocEdu;
import cn.ffcs.uec.staff.model.UecEnc;
import cn.ffcs.uec.staff.model.UecFamily;
import cn.ffcs.uec.staff.model.UecNationduty;
import cn.ffcs.uec.staff.model.UecPartyLog;
import cn.ffcs.uec.staff.model.UecPsndocWadoc;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uec.staff.model.UecPunish;
import cn.ffcs.uec.staff.model.UecTalentTeam;
import cn.ffcs.uec.staff.model.UecTitle;
import cn.ffcs.uec.staff.model.UecTrial;
import cn.ffcs.uec.staffRecords.manager.AtiSpecificFormManager;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.NumericUtil;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;

@Controller
@Scope("prototype")
public class RecordsApprovalListBoxExt extends Div implements IdSpace {

	/**
	 * 
	 */
	private static final long serialVersionUID = -550778452631967868L;

	public static final String RECORDS_APPROVAL_LISTBOX_EXT_ZUL = "/pages_nmg/recordsApproval/comp/recordsApproval_listbox_ext.zul";

	@Getter
	private RecordsApprovalListBoxExtBean bean = new RecordsApprovalListBoxExtBean();

	/**
	 * 审批列表
	 */
	private List<TaskVo> tasks = new ArrayList<TaskVo>();

	/**
	 * 选中的任务
	 */
	private List<TaskVo> selectedTasks = new ArrayList<TaskVo>();

	@Resource
	private AtiSpecificFormManager atiSpecificFormManager = (AtiSpecificFormManager) ApplicationContextUtil
			.getBean("atiSpecificFormManager");

	private ActRunTaskManager actRunTaskManager = (ActRunTaskManager) ApplicationContextUtil
			.getBean("actRunTaskManager");

	private static UecOutStaffManager uecOutStaffManager = (UecOutStaffManager) ApplicationContextUtil
			.getBean("uecOutStaffManager");

	private static UecTrialManager uecTrialManager = (UecTrialManager) ApplicationContextUtil
			.getBean("uecTrialManager");

	private static UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil
			.getBean("uecPsnjobManager");

	private static UecPsndocWadocManager uecPsndocWadocManager = (UecPsndocWadocManager) ApplicationContextUtil
			.getBean("uecPsndocWadocManager");

	private static UecEncManager uecEncManager = (UecEncManager) ApplicationContextUtil
			.getBean("uecEncManager");

	private static UecPunishManager uecPunishManager = (UecPunishManager) ApplicationContextUtil
			.getBean("uecPunishManager");

	private static UecAssManager uecAssManager = (UecAssManager) ApplicationContextUtil
			.getBean("uecAssManager");

	private static UecTalentTeamManager uecTalentTeamManager = (UecTalentTeamManager) ApplicationContextUtil
			.getBean("uecTalentTeamManager");

	private static UecDocEduManager uecDocEduManager = (UecDocEduManager) ApplicationContextUtil
			.getBean("uecDocEduManager");

	private static UecTitleManager uecTitleManager = (UecTitleManager) ApplicationContextUtil
			.getBean("uecTitleManager");

	private static UecPartyLogManager uecPartyLogManager = (UecPartyLogManager) ApplicationContextUtil
			.getBean("uecPartyLogManager");

	private static UecFamilyManager uecFamilyManager = (UecFamilyManager) ApplicationContextUtil
			.getBean("uecFamilyManager");

	private static UecNationdutyManager uecNationdutyManager = (UecNationdutyManager) ApplicationContextUtil
			.getBean("uecNationdutyManager");

	private static UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();

	@Getter
	@Setter
	private String type;

	/**
	 * 构造函数
	 */
	public RecordsApprovalListBoxExt() {
		Executions.createComponents(RECORDS_APPROVAL_LISTBOX_EXT_ZUL, this,
				null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');

	}

	/**
	 * 初始化
	 */
	public void onCreate() {
		this.bindCombobox();
		this.setButtonDisabled(true, true, true, true);
		this.setButtonVisible(false, true);

		/**
		 * 多选
		 */
		this.bean.getRecordsApprovalListbox().setCheckmark(true);
		this.bean.getRecordsApprovalListbox().setMultiple(true);

		onQuery();

	}

	private void bindCombobox() {
		List<NodeVo> nodeVoList = new ArrayList<NodeVo>();
		String[][] option = { { "66", "信息修改" }, { "67", "入职" }, { "68", "转正" },
				{ "69", "调配" }, { "70", "调薪" }, { "71", "离职" } };
		for (int i = 0; i < option.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(option[i][j]);
				nodeVo.setName(option[i][j + 1]);
			}
			nodeVoList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getCategoryId(), nodeVoList);

	}

	public void onReset() {
		PubUtil.clearComponent(this);
		tasks.clear();
		selectedTasks.clear();
		outStaffInfo = UecOutStaffInfo.newInstance();
	}

	/**
	 * onQuery
	 */

	public void onQuery() {
		if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
			ZkUtil.showError("当前登录用户已失效，请重新登录!", "错误提示");
			return;
		}
		this.bean.getRecordsApprovalListboxPaging().setActivePage(0);

		this.initStaffEntryTasks();

		this.queryTask();
	}

	/**
	 * 初始化员工入职流程待办任务
	 */
	private void initStaffEntryTasks() {
		tasks.clear();
		selectedTasks.clear();
		List<TaskVo> taskList = ApprovalUtil.approvalTodo();
		if (null == taskList) {
			return;
		}
		if (StrUtil.isNullOrEmpty(type)) {
			tasks = taskList;
			return;
		}
		for (TaskVo taskVo : taskList) {
			String[] typeArray = type.split(",");
			for (String str : typeArray) {
				if (str != null && str.equals(taskVo.getProcDefKey())) {
					tasks.add(taskVo);
				}
			}
		}
	}

	public void queryTask() {
		int activePage = bean.getRecordsApprovalListboxPaging().getActivePage();
		int pageSize = bean.getRecordsApprovalListboxPaging().getPageSize();

		// 根据页面参数获取list
		Listitem selectedItemListitem = this.bean.getCategoryId()
				.getSelectedItem();
		String categoryId = null;
		if (null != selectedItemListitem) {
			categoryId = (String) this.bean.getCategoryId().getSelectedItem()
					.getValue();
		}

		Date beginDate = this.bean.getStartTime().getValue();
		Date endDate = this.bean.getEndTime().getValue();
		List<TaskVo> taskList = this.getTaskList(tasks, categoryId, beginDate,
				endDate);

		if (null != taskList && taskList.size() > 0) {
			bean.getRecordsApprovalListboxPaging().setTotalSize(
					NumericUtil.nullToZero(taskList.size()));

			// 根据当前页和页数获取list
			List<TaskVo> taskPageList = getPageList(taskList, activePage,
					pageSize);

			ListModel dataList = new BindingListModelList(taskPageList, true);
			bean.getRecordsApprovalListbox().setModel(dataList);
		}

		else {
			PubUtil.clearListbox(bean.getRecordsApprovalListbox());
		}

	}

	/**
	 * 选中多条待办记录
	 */
	public synchronized void onSelectRequest() {
		if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
			ZkUtil.showError("当前登录用户已失效，请重新登录!", "错误提示");
			return;
		}
		int selCount = bean.getRecordsApprovalListbox().getSelectedCount();
		if (selCount > 0) {

			Set set = bean.getRecordsApprovalListbox().getSelectedItems();
			List<Listitem> list = new ArrayList<Listitem>();
			list.addAll(set);
			selectedTasks.clear();
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					selectedTasks.add((TaskVo) list.get(i).getValue());
				}
			}
			if (selectedTasks.size() > 0) {
				for (TaskVo taskVo : selectedTasks) {
					if ("modify".equals(taskVo.getTaskDefKey())) {
						setButtonDisabled(false, true, true, true);
						setButtonVisible(true, false);
						break;
					} else {
						setButtonDisabled(true, false, false, false);
						setButtonVisible(false, true);
					}
				}
			}

			if (selCount == 1) {
				// 显示单个流程的流转信息
				Events.postEvent(ApprovalConstants.ON_SELECTED_TASK, this,
						selectedTasks.get(0));
			}
		} else {
			selectedTasks.clear();
			setButtonDisabled(true, true, true, true);
			setButtonVisible(false, true);
			Events.postEvent(ApprovalConstants.ON_SELECTED_TASK, this, null);
		}

	}

	/**
	 * 审批一条记录
	 */
	public void onApproval() {
		if (null == selectedTasks || selectedTasks.size() != 1) {
			ZkUtil.showError("请选择一条记录！", "错误提示");
			onQuery();
			return;
		}
		final TaskVo task = (TaskVo) this.bean.getRecordsApprovalListbox()
				.getSelectedItem().getValue();
		final String procInstId = task.getProcInsId();
		final AtiOaBaseObject oaBaseObject = atiSpecificFormManager
				.getAtiOaBaseObjectByProcInstId(procInstId);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("taskDefKey", task.getTaskDefKey());
		map.put("procDefName", task.getProcDefName());
		map.put("procDefKey", task.getProcDefKey());
		map.put("taskId", task.getTaskId());
		// 向弹框 中传入不同对象
		// final UomEntity object = (UomEntity) this
		// .approvalViewObject(oaBaseObject);
		// map.put("object", object);
		map.put("oaBaseObject", oaBaseObject);
		Window window = null;
		if (ApprovalUtil.OUT_STAFF_ENTRY.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_ENTRY_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_TRIAL.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_TRIAL_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_ADJUST_EDIT.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_ADJUST_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_RETIRE.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_LEAVE_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_ADJUST_POST.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_ADJUST_POST_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_ENC_EDIT.equals(task.getProcDefKey())) {
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_ENC_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_EDU_ADD.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_ADD);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_EDU_ADD_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_EDU_EDIT.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_EDU_EDIT_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_PUNISH_EDIT.equals(task.getProcDefKey())) {
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_PUNISH_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_ASS_EDIT.equals(task.getProcDefKey())) {
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_ASS_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_TALENT_TEAM_EDIT
				.equals(task.getProcDefKey())) {
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_TALENT_TEAM_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_TITLE_EDIT.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_TITLE_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_TITLE_ADD.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_ADD);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_TITLE_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_PARTYLOG_ADD.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_ADD);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_PARTYLOG_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_PARTYLOG_EDIT.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_PARTYLOG_VIEW, this, map);
		}
		if (ApprovalUtil.OUT_STAFF_WORKDATE_EDIT.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.OUT_STAFF_WORKDATE_VIEW, this, map);
		}
		if (ApprovalUtil.STAFF_ADJUST_POST.equals(task.getProcDefKey())) {
			map.put("opType", ApprovalConstants.OP_TYPE_EDIT);
			window = (Window) Executions.createComponents(
					ApprovalConstants.STAFF_ADJUST_POST_VIEW, this, map);
		}

		try {
			window.doModal();
			// 审批同意
			window.addEventListener("onApprovalResponse", new EventListener() {

				@SuppressWarnings("unchecked")
				@Override
				public void onEvent(Event event) throws Exception {
					if (null != event.getData()) {
						Map<String, Object> map = (Map<String, Object>) event
								.getData();
						// 签收任务
						boolean isAssign = ApprovalUtil.claim(task.getTaskId());
						if (!isAssign) {
							ZkUtil.showError("任务不存在或已处理完毕！", "错误提示");
							onQuery();
							return;
						}
						// 完成任务
						boolean isComplete = ApprovalUtil.approvalPostHttp(map
								.get("comment").toString(),
								map.get("onApprovalResult").toString(), task
										.getTaskId(), task.getProcInsId());
						if (!isComplete) {
							ZkUtil.showError("任务不存在或已处理完毕!", "错误提示");
							onQuery();
							return;
						}

						// 审批同意后，状态设置为生效

						List<Map<String, Object>> list = actRunTaskManager
								.getRuTasks(task.getProcInsId());
						if (null == list) {
							ZkUtil.showError("未知错误!请联系管理员。", "错误信息");
							return;
						}
						// 审批数据生效，原数据失效
						if (list.size() == 0) {
							setDataStatus(oaBaseObject, task);
							ZkUtil.showInformation("流程已结束，请查看数据！", "温馨提示");
						}
						// 流程未结束，提示下一审批人
						if (list.size() > 0) {
							String tip = "审批已提交，下一审批人：";
							showCurrentName(procInstId, tip);
						}

						// 刷新列表
						onQuery();

						postEventsToHistoricFlow(task);

					}
				}
			});
			// 审批拒绝
			window.addEventListener("onRejectResponse", new EventListener() {

				@SuppressWarnings("unchecked")
				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						Map<String, Object> map = (Map<String, Object>) event
								.getData();
						// 签收
						boolean isAssign = ApprovalUtil.claim(task.getTaskId());
						if (!isAssign) {
							ZkUtil.showError("任务不存在或已处理完毕！", "错误提示");
							onQuery();
							return;
						}
						// 处理任务
						boolean isComplete = ApprovalUtil.approvalPostHttp(map
								.get("comment").toString(),
								map.get("onRejectResult").toString(), task
										.getTaskId(), task.getProcInsId());
						if (!isComplete) {
							ZkUtil.showError("任务不存在或已处理完毕!", "错误提示");
							onQuery();
							return;
						}
						String tip = "审批已提交，退回到发起人：";
						showCurrentName(procInstId, tip);
						onQuery();

						postEventsToHistoricFlow(task);
					}
				}
			});
			// 重新申请
			window.addEventListener("onOKResponse", new EventListener() {

				@Override
				public void onEvent(Event event) throws Exception {
					if (event.getData() != null) {
						String onOKResult = (String) event.getData();
						// 发起人默认已签收

						// 处理任务
						boolean isComplete = ApprovalUtil.approvalPostHttp(
								null, onOKResult, task.getTaskId(),
								task.getProcInsId());
						if (!isComplete) {
							ZkUtil.showError("任务不存在或已处理完毕!", "错误提示");
							onQuery();
							return;
						}

						ApprovalUtil.isCurrentAssignNames(task.getProcInsId());
						String tip = "审批已提交，下一审批人：";
						showCurrentName(procInstId, tip);

						onQuery();

						postEventsToHistoricFlow(task);
					}
				}
			});
			// 刷新列表
			window.addEventListener(
					ApprovalConstants.ON_REFRESH_QUERY_RESPONSE,
					new EventListener() {
						@Override
						public void onEvent(Event event) throws Exception {
							onQuery();
						}
					});

		} catch (SuspendNotAllowedException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 显示当前办理人
	 */
	public void showCurrentName(String procInstId, String tip) {
		Map<String, Object> currentTaskMap = ApprovalUtil
				.getCurrentAssignNames(procInstId);
		@SuppressWarnings("unchecked")
		List<String> names = (List<String>) currentTaskMap.get("names");
		AtiUser atiUser = new AtiUser();
		AtiUserManager atiUserManager = (AtiUserManager) ApplicationContextUtil
				.getBean("atiUserManager");
		atiUser.setNo(names.get(0));
		atiUser = atiUserManager.findAtiUserByAtiUser(atiUser);
		ZkUtil.showInformation(tip + atiUser.getName(), "温馨提示");

	}

	/**
	 * 抛事件 获取流程流转信息
	 * 
	 * @param taskVo
	 */
	private void postEventsToHistoricFlow(TaskVo taskVo) {
		Events.postEvent(ApprovalConstants.ON_SELECTED_TASK, this, taskVo);
	}

	/**
	 * 提交
	 */
	public void onPost() {
		this.onApproval();
	}

	/**
	 * 批量审批通过
	 * 
	 * @throws InterruptedException
	 */
	public void onApprovalAll() throws InterruptedException {

		Messagebox.show("确认全部审批所选记录？", "输入确认", Messagebox.OK
				| Messagebox.CANCEL, Messagebox.QUESTION, new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				if (((Integer) event.getData()).intValue() == Messagebox.OK) {
					approvalAll();
				} else {
					return;
				}
			}
		});

	}

	/**
	 * 批量审批通过
	 * 
	 * @throws InterruptedException
	 */
	private void approvalAll() throws InterruptedException {
		if (null == selectedTasks || selectedTasks.size() == 0) {
			ZkUtil.showError("没有待审批的任务！", "错误提示");
			onQuery();
			return;
		}
		for (TaskVo taskVo : selectedTasks) {

			boolean flag = ApprovalUtil.claim(taskVo.getTaskId());
			if (!flag) {
//				ZkUtil.showError("存在已处理完毕的任务，请重新提交！", "错误提示");
//				onQuery();
				continue;
			}

			ApprovalUtil.approvalPostHttp("[批量审批:同意]",
					ApprovalConstants.ON_APPROVAL_RESULT, taskVo.getTaskId(),
					taskVo.getProcInsId());
			// 流程结束后 ， 审批数据生效，原数据失效
			List<Map<String, Object>> list = actRunTaskManager
					.getRuTasks(taskVo.getProcInsId());
			if (null == list) {
				ZkUtil.showError("未知错误!", "错误信息");
				return;
			}
			// 流程结束，修改状态
			if (list.size() == 0) {
				AtiOaBaseObject oaBaseObject = atiSpecificFormManager
						.getAtiOaBaseObjectByProcInstId(taskVo.getProcInsId());
				setDataStatus(oaBaseObject, taskVo);
				// ZkUtil.showInformation("流程已结束，请查看数据！", "温馨提示");
			}
			// 流程未结束，继续执行
			if (list.size() > 0) {
				ApprovalUtil.isCurrentAssignNames(taskVo.getProcInsId());
			}

		}

		postEventsToHistoricFlow(selectedTasks.get(selectedTasks.size() - 1));

		ZkUtil.showInformation("批量审批已完成!", "温馨提示");
		onQuery();
	}

	/**
	 * 批量审批驳回
	 * 
	 * @throws InterruptedException
	 */
	public void onRejectAll() throws InterruptedException {

		Messagebox.show("确认全部审批所选记录？", "输入确认", Messagebox.OK
				| Messagebox.CANCEL, Messagebox.QUESTION, new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				if (((Integer) event.getData()).intValue() == Messagebox.OK) {
					rejectAll();
				} else {
					return;
				}
			}
		});

	}

	private void rejectAll() throws InterruptedException {
		if (null == selectedTasks || selectedTasks.size() == 0) {
			ZkUtil.showError("没有待审批的任务！", "错误提示");
			return;
		}
		for (TaskVo taskVo : selectedTasks) {
			boolean isAssign = ApprovalUtil.claim(taskVo.getTaskId());
			if (!isAssign) {
//				ZkUtil.showError("存在已处理完毕的任务，请重新提交！", "错误提示");
//				onQuery();
				continue;
			}
			ApprovalUtil.approvalPostHttp("[批量审批:驳回]",
					ApprovalConstants.ON_REJECT_RESULT, taskVo.getTaskId(),
					taskVo.getProcInsId());
		}

		postEventsToHistoricFlow(selectedTasks.get(selectedTasks.size() - 1));

		ZkUtil.showInformation("批量审批已完成!", "温馨提示");
		onQuery();
	}

	/**
	 * 设置按钮Disabled
	 * 
	 * @param canPost
	 * @param canApproval
	 * @param canApprovalAll
	 * @param canRejectAll
	 */
	private void setButtonDisabled(Boolean canPost, Boolean canApproval,
			Boolean canApprovalAll, Boolean canRejectAll) {
		bean.getPost().setDisabled(canPost);
		bean.getApproval().setDisabled(canApproval);
		bean.getApprovalAll().setDisabled(canApprovalAll);
		bean.getRejectAll().setDisabled(canRejectAll);
	}

	/**
	 * 设置按钮可见
	 * 
	 * @param canPost
	 * @param canApproval
	 */
	private void setButtonVisible(Boolean canPost, Boolean canApproval) {
		bean.getPost().setVisible(canPost);
		bean.getApproval().setVisible(canApproval);
	}

	/**
	 * 获取当前页的任务
	 * 
	 * @param list
	 * @param activePage
	 * @param pageSize
	 * @return
	 */
	public List<TaskVo> getPageList(List<TaskVo> list, int activePage,
			int pageSize) {
		int fromIndex = activePage * pageSize;
		int toIndex = fromIndex + pageSize;
		if (fromIndex >= list.size()) {
			return null;
		}
		if (toIndex >= list.size()) {
			return list.subList(fromIndex, list.size());
		}
		return list.subList(fromIndex, toIndex);

	}

	/**
	 * 根据页面参数获取待办列表
	 */
	@SuppressWarnings("unchecked")
	public List<TaskVo> getTaskList(List<TaskVo> list, String categoryId,
			Date beginDate, Date endDate) {
		List<TaskVo> taskList = new ArrayList<TaskVo>();
		Map<String, Object> map = null;
		if (StrUtil.isNullOrEmpty(categoryId)) {
			if (StrUtil.isNullOrEmpty(beginDate)
					&& !StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if ((Long) map.get("formSenderTime") <= endDate.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
			if (!StrUtil.isNullOrEmpty(beginDate)
					&& StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if ((Long) map.get("formSenderTime") >= beginDate.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
			if (!StrUtil.isNullOrEmpty(beginDate)
					&& !StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if ((Long) map.get("formSenderTime") >= beginDate.getTime()
							&& (Long) map.get("formSenderTime") <= endDate
									.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
		}
		if (!StrUtil.isNullOrEmpty(categoryId)) {
			if (StrUtil.isNullOrEmpty(beginDate)
					&& !StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if (categoryId.equals(map.get("categoryId").toString())
							&& (Long) map.get("formSenderTime") <= endDate
									.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
			if (!StrUtil.isNullOrEmpty(beginDate)
					&& StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if (categoryId.equals(map.get("categoryId").toString())
							&& (Long) map.get("formSenderTime") >= beginDate
									.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
			if (!StrUtil.isNullOrEmpty(beginDate)
					&& !StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if (categoryId.equals(map.get("categoryId").toString())
							&& (Long) map.get("formSenderTime") >= beginDate
									.getTime()
							&& (Long) map.get("formSenderTime") <= endDate
									.getTime()) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
			if (StrUtil.isNullOrEmpty(beginDate)
					&& StrUtil.isNullOrEmpty(endDate)) {
				for (TaskVo taskVo : list) {
					map = (Map<String, Object>) taskVo.getVars().get("map");
					if (categoryId.equals(map.get("categoryId").toString())) {
						taskList.add(taskVo);
					}
				}
				return taskList;
			}
		}
		return tasks;

	}

	public void onListboxPaging() {
		queryTask();
		selectedTasks.clear();
		
	}

	/**
	 * 返回弹框中的对象
	 */
	public Object approvalViewObject(AtiOaBaseObject oaBaseObject, TaskVo task) {

		return null;

	}

	/**
	 * 流程结束后数据库修改记录状态：历史数据失效，审批数据生效
	 * 
	 * @param oaBaseObject
	 */
	public static void setDataStatus(AtiOaBaseObject oaBaseObject, TaskVo taskVo) {
		// 1.外包人员入职 , uec_out_staff_info 修改一条记录，uec_trial 添加一条记录
		if (ApprovalUtil.OUT_STAFF_ENTRY.equals(taskVo.getProcDefKey())) {

			UecTrial trial = UecTrial.newInstance();
			trial.setTrialId(Long.parseLong(oaBaseObject.getTrialId()));
			trial = uecTrialManager.findUecTrialById(trial);
			trial.updateStatusCdIs0();

			setOutStaffInfoStatus(oaBaseObject);

			String eduIds = oaBaseObject.getEduId();
			if (!StrUtil.isNullOrEmpty(eduIds)) {
				String[] eduIdArray = eduIds.split("-");
				for (String eduId : eduIdArray) {
					UecDocEdu uecDocEdu = UecDocEdu.newInstance();
					uecDocEdu.setEduId(Long.valueOf(eduId));
					uecDocEdu = uecDocEduManager.findUecDocEdu(uecDocEdu);
					uecDocEdu.updateStatusCdIs0();
				}
			}
			String familyIds = oaBaseObject.getFamilyId();
			if (!StrUtil.isNullOrEmpty(familyIds)) {
				String[] familyIdArray = familyIds.split("-");
				for (String familyID : familyIdArray) {
					UecFamily uecFamily = UecFamily.newInstance();
					uecFamily.setFamilyId(Long.valueOf(familyID));
					uecFamily = uecFamilyManager.queryUecFamilyById(uecFamily);
					uecFamily.updateStatusCdIs0();
				}
			}
			String titleIds = oaBaseObject.getTitleId();
			if (!StrUtil.isNullOrEmpty(titleIds)) {
				String[] titleIdArray = titleIds.split("-");
				for (String titleId : titleIdArray) {
					UecTitle uecTitle = UecTitle.newInstance();
					uecTitle.setTitleId(Long.valueOf(titleId));
					uecTitle = uecTitleManager.findUecTitleById(uecTitle);
					uecTitle.updateStatusCdIs0();
				}
			}
			String nationdutyIds = oaBaseObject.getNationdutyId();
			if (!StrUtil.isNullOrEmpty(nationdutyIds)) {
				String[] nationdutyIdArray = nationdutyIds.split("-");
				for (String nationdutyId : nationdutyIdArray) {
					UecNationduty uecNationduty = UecNationduty.newInstance();
					uecNationduty.setNationdutyId(Long.valueOf(nationdutyId));
					uecNationduty = uecNationdutyManager
							.queryUecNationdutyByNationdutyId(uecNationduty);
					uecNationduty.updateStatusCdIs0();
				}
			}
			String encIds = oaBaseObject.getEncId();
			if (!StrUtil.isNullOrEmpty(encIds)) {
				String[] encIdArray = encIds.split("-");
				for (String encId : encIdArray) {
					UecEnc uecEnc = UecEnc.newInstance();
					uecEnc.setEncId(Long.valueOf(encId));
					uecEnc = uecEncManager.findUecEncById(uecEnc);
					uecEnc.updateStatusCdIs0();
				}
			}
			String punishIds = oaBaseObject.getPunishId();
			if (!StrUtil.isNullOrEmpty(punishIds)) {
				String[] punishIdArray = punishIds.split("-");
				for (String punishId : punishIdArray) {
					UecPunish uecPunish = UecPunish.newInstance();
					uecPunish.setPunishId(Long.valueOf(punishId));
					uecPunish = uecPunishManager.findUecPunishById(uecPunish);
					uecPunish.updateStatusCdIs0();
				}
			}
			String partyLogIds = oaBaseObject.getPartyLogId();
			if (!StrUtil.isNullOrEmpty(partyLogIds)) {
				String[] partyLogIdArray = partyLogIds.split("-");
				for (String partyLogId : partyLogIdArray) {
					UecPartyLog uecPartyLog = UecPartyLog.newInstance();
					uecPartyLog.setPartylogId(Long.valueOf(partyLogId));
					uecPartyLog = uecPartyLogManager
							.findUecPartyLogById(uecPartyLog);
					uecPartyLog.updateStatusCdIs0();
				}
			}

		}
		// 2.外包人员转正
		if (ApprovalUtil.OUT_STAFF_TRIAL.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			UecTrial uecTrial = UecTrial.newInstance();
			uecTrial.setTrialId(Long.parseLong(oaBaseObject.getTrialIdHis()));
			uecTrial = uecTrialManager.findUecTrialById(uecTrial);
			UecTrial trialTmp = (UecTrial) uecTrial.clone();
			// 修改原数据为审批数据
			UecTrial trialApproval = UecTrial.newInstance();
			trialApproval.setTrialId(Long.parseLong(oaBaseObject.getTrialId()));
			trialApproval = uecTrialManager.findUecTrialById(trialApproval);
			trialApproval.setTrialId(Long.parseLong(oaBaseObject
					.getTrialIdHis()));
			trialApproval.updateStatusCdIs0();
			// 修改审批数据为历史数据
			trialTmp.setTrialId(Long.parseLong(oaBaseObject.getTrialId()));
			trialTmp.updateStatusCdIs1();

			setPsnJobStatus(oaBaseObject);

			setOutStaffInfoStatus(oaBaseObject);
		}
		// 3.外包人员调配
		if (ApprovalUtil.OUT_STAFF_ADJUST_EDIT.equals(taskVo.getProcDefKey())) {
			setPsnJobStatus(oaBaseObject);
			setOutStaffInfoStatus(oaBaseObject);
		}
		// 4. 外包人员 离退流程
		if (ApprovalUtil.OUT_STAFF_RETIRE.equals(taskVo.getProcDefKey())) {
			setPsnJobStatus(oaBaseObject);
		}
		// 5.外包人员 定调资
		if (ApprovalUtil.OUT_STAFF_ADJUST_POST.equals(taskVo.getProcDefKey())
				|| ApprovalUtil.STAFF_ADJUST_POST
						.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			UecPsndocWadoc psndocWadocHis = UecPsndocWadoc.newInstance();
			psndocWadocHis.setWadocId(Long.parseLong(oaBaseObject
					.getWadocIdHis()));
			psndocWadocHis = uecPsndocWadocManager
					.findUecPsndocWadocById(psndocWadocHis);
			UecPsndocWadoc psndocWadocTmp = (UecPsndocWadoc) psndocWadocHis
					.clone();

			// 修改原数据 为 审批数据
			UecPsndocWadoc psndocWadocApproval = UecPsndocWadoc.newInstance();
			psndocWadocApproval.setWadocId(Long.parseLong(oaBaseObject
					.getWadocIdModify()));
			psndocWadocApproval = uecPsndocWadocManager
					.findUecPsndocWadocById(psndocWadocApproval);
			psndocWadocApproval.setWadocId(Long.parseLong(oaBaseObject
					.getWadocIdHis()));
			psndocWadocApproval.updateStatusCdIs0();

			// 修改 审批数据 为 历史数据
			psndocWadocTmp.setWadocId(Long.parseLong(oaBaseObject
					.getWadocIdModify()));
			psndocWadocTmp.updateStatusCdIs1();

			// 外包定调资 添加了一条记录
			if (ApprovalUtil.OUT_STAFF_ADJUST_POST.equals(taskVo
					.getProcDefKey())) {
				if (!StrUtil.isNullOrEmpty(oaBaseObject.getWadocIdAdd())) {
					// 新增一条数据直接生效
					UecPsndocWadoc psndocWadocAdd = UecPsndocWadoc
							.newInstance();
					psndocWadocAdd.setWadocId(Long.valueOf(oaBaseObject
							.getWadocIdAdd()));
					psndocWadocAdd = uecPsndocWadocManager
							.findUecPsndocWadocById(psndocWadocAdd);
					psndocWadocAdd.updateStatusCdIs0();
				}
			}

		}
		// 6.外包人员奖励
		if (ApprovalUtil.OUT_STAFF_ENC_EDIT.equals(taskVo.getProcDefKey())) {
			String encId = oaBaseObject.getEncId();
			UecEnc uecEnc = UecEnc.newInstance();
			uecEnc.setEncId(Long.parseLong(encId));
			uecEnc = uecEncManager.findUecEncById(uecEnc);
			uecEnc.updateStatusCdIs0();
		}
		// 7.外包人员惩罚
		if (ApprovalUtil.OUT_STAFF_PUNISH_EDIT.equals(taskVo.getProcDefKey())) {
			String punishId = oaBaseObject.getPunishId();
			UecPunish uecPunish = UecPunish.newInstance();
			uecPunish.setPunishId(Long.parseLong(punishId));
			uecPunish = uecPunishManager.findUecPunishById(uecPunish);
			uecPunish.updateStatusCdIs0();
		}
		// 8.外包人员专业人才
		if (ApprovalUtil.OUT_STAFF_TALENT_TEAM_EDIT.equals(taskVo
				.getProcDefKey())) {
			String talentTeamId = oaBaseObject.getTalentTeamId();
			UecTalentTeam uecTalentTeam = UecTalentTeam.newInstance();
			uecTalentTeam.setTalentTeamId(Long.parseLong(talentTeamId));
			uecTalentTeam = uecTalentTeamManager
					.findUecTalentTeamById(uecTalentTeam);
			uecTalentTeam.updateStatusCdIs0();
		}

		// 9.外包人员教育经历新增
		if (ApprovalUtil.OUT_STAFF_EDU_ADD.equals(taskVo.getProcDefKey())) {
			String eduId = oaBaseObject.getEduId();
			UecDocEdu uecDocEdu = UecDocEdu.newInstance();
			uecDocEdu.setEduId(Long.parseLong(eduId));
			uecDocEdu = uecDocEduManager.findUecDocEdu(uecDocEdu);
			changeEdu(uecDocEdu);
			uecDocEdu.updateStatusCdIs0();
		}
		// 10.外包人员教育经历修改
		if (ApprovalUtil.OUT_STAFF_EDU_EDIT.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			UecDocEdu uecDocEduHis = UecDocEdu.newInstance();
			uecDocEduHis.setEduId(Long.parseLong(oaBaseObject.getEduIdHis()));
			uecDocEduHis = uecDocEduManager.findUecDocEdu(uecDocEduHis);
			UecDocEdu eduTmp = (UecDocEdu) uecDocEduHis.clone();

			// 修改原数据为审批数据
			UecDocEdu uecDocEdu = UecDocEdu.newInstance();
			uecDocEdu.setEduId(Long.parseLong(oaBaseObject.getEduId()));
			uecDocEdu = uecDocEduManager.findUecDocEdu(uecDocEdu);
			uecDocEdu.setEduId(Long.parseLong(oaBaseObject.getEduIdHis()));
			changeEdu(uecDocEdu);
			uecDocEdu.updateStatusCdIs0();

			// 修改审批数据为历史数据
			eduTmp.setEduId(Long.parseLong(oaBaseObject.getEduId()));
			eduTmp.updateStatusCdIs1();
		}

		// 11.外包人员专业技术职务 新增
		if (ApprovalUtil.OUT_STAFF_TITLE_ADD.equals(taskVo.getProcDefKey())) {
			String titleId = oaBaseObject.getTitleId();
			UecTitle uecTitle = UecTitle.newInstance();
			uecTitle.setTitleId(Long.valueOf(titleId));
			uecTitle = uecTitleManager.findUecTitleById(uecTitle);
			uecTitle.updateStatusCdIs0();
		}
		// 12. 外包人员专业技术职务 修改
		if (ApprovalUtil.OUT_STAFF_TITLE_EDIT.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			UecTitle uecTitle = UecTitle.newInstance();
			uecTitle.setTitleId(Long.valueOf(oaBaseObject.getTitleIdHis()));
			uecTitle = uecTitleManager.findUecTitleById(uecTitle);
			UecTitle titleTmp = uecTitle.clone();
			// 修改原数据为审批数据
			UecTitle uecTitleApproval = UecTitle.newInstance();
			uecTitleApproval
					.setTitleId(Long.valueOf(oaBaseObject.getTitleId()));
			uecTitleApproval = uecTitleManager
					.findUecTitleById(uecTitleApproval);
			uecTitleApproval.setTitleId(Long.valueOf(oaBaseObject
					.getTitleIdHis()));
			uecTitleApproval.updateStatusCdIs0();
			// 修改审批数据为历史数据
			titleTmp.setTitleId(Long.valueOf(oaBaseObject.getTitleId()));
			titleTmp.updateStatusCdIs1();
		}
		// 13. 外包人员政治面貌新增
		if (ApprovalUtil.OUT_STAFF_PARTYLOG_ADD.equals(taskVo.getProcDefKey())) {
			UecPartyLog uecPartyLog = UecPartyLog.newInstance();
			uecPartyLog
					.setPartylogId(Long.valueOf(oaBaseObject.getPartyLogId()));
			uecPartyLog = uecPartyLogManager.findUecPartyLogById(uecPartyLog);
			uecPartyLog.updateStatusCdIs0();
		}
		// 14. 外包人员政治面貌修改
		if (ApprovalUtil.OUT_STAFF_PARTYLOG_EDIT.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			UecPartyLog uecPartyLogHis = UecPartyLog.newInstance();
			uecPartyLogHis.setPartylogId(Long.valueOf(oaBaseObject
					.getPartyLogIdHis()));
			uecPartyLogHis = uecPartyLogManager
					.findUecPartyLogById(uecPartyLogHis);
			UecPartyLog partyLogTmp = (UecPartyLog) uecPartyLogHis.clone();
			// 修改原数据为审批数据
			UecPartyLog partyLogApproval = UecPartyLog.newInstance();
			partyLogApproval.setPartylogId(Long.valueOf(oaBaseObject
					.getPartyLogId()));
			partyLogApproval = uecPartyLogManager
					.findUecPartyLogById(partyLogApproval);
			partyLogApproval.setPartylogId(Long.valueOf(oaBaseObject
					.getPartyLogIdHis()));
			partyLogApproval.updateStatusCdIs0();
			// 修改审批数据为历史数据
			partyLogTmp
					.setPartylogId(Long.valueOf(oaBaseObject.getPartyLogId()));
			partyLogTmp.updateStatusCdIs1();
		}
		// 15. 外包人员工作日期修改
		if (ApprovalUtil.OUT_STAFF_WORKDATE_EDIT.equals(taskVo.getProcDefKey())) {
			// 保存原数据
			// UecTitle uecTitle = UecTitle.newInstance();
			// uecTitle.setTitleId(Long.valueOf(primaryIdHis));
			// uecTitle = uecTitleManager.findUecTitleById(uecTitle);
			// UecTitle titleTmp = uecTitle.clone();
			// // 修改原数据为审批数据
			// UecTitle uecTitleApproval = UecTitle.newInstance();
			// uecTitleApproval
			// .setTitleId(Long.valueOf(oaBaseObject.getTitleId()));
			// uecTitleApproval = uecTitleManager
			// .findUecTitleById(uecTitleApproval);
			// uecTitleApproval.setTitleId(Long.valueOf(primaryIdHis));
			// uecTitleApproval.updateStatusCdIs0();
			// // 修改审批数据为历史数据
			// titleTmp.setTitleId(Long.valueOf(oaBaseObject.getTitleId()));
			// titleTmp.updateStatusCdIs1();

			// setOutStaffInfoStatus(oaBaseObject,
			// uecTitle.getStaffId().toString());
			setOutStaffInfoStatus(oaBaseObject);
		}
		// 16. 外包人员考核信息新增
		if (ApprovalUtil.OUT_STAFF_ASS_EDIT.equals(taskVo.getProcDefKey())) {
			String assId = oaBaseObject.getAssId();
			UecAss uecAss = UecAss.newInstance();
			uecAss.setAssId(Long.parseLong(assId));
			uecAss = uecAssManager.findUecAssById(uecAss);
			uecAss.updateStatusCdIs0();
		}
	}

	/**
	 * 修改人员信息记录状态
	 * 
	 * @param oaBaseObject
	 * @param primaryIdHis
	 */
	private static void setOutStaffInfoStatus(AtiOaBaseObject oaBaseObject) {
		// 保存原数据
		outStaffInfo.setOutStaffId(Long.parseLong(oaBaseObject
				.getOutStaffIdHis()));
		outStaffInfo = uecOutStaffManager
				.findUecOutStaffInfoByOutStaffId(outStaffInfo);
		UecOutStaffInfo tmpOutStaffInfo = (UecOutStaffInfo) outStaffInfo
				.clone();

		// 修改原数据 为 审批数据
		outStaffInfo = UecOutStaffInfo.newInstance();
		outStaffInfo
				.setOutStaffId(Long.parseLong(oaBaseObject.getOutStaffId()));
		outStaffInfo = uecOutStaffManager
				.findUecOutStaffInfoByOutStaffId(outStaffInfo);
		outStaffInfo.setOutStaffId(Long.parseLong(oaBaseObject
				.getOutStaffIdHis()));
		outStaffInfo.updateStatusCdIs0();

		// 修改审批数据为历史数据
		tmpOutStaffInfo.setOutStaffId(Long.parseLong(oaBaseObject
				.getOutStaffId()));
		tmpOutStaffInfo.updateStatusCdIs1();
	}

	/**
	 * 修改任职记录信息状态
	 * 
	 * @param oaBaseObject
	 * @param primaryIdHis
	 */
	private static void setPsnJobStatus(AtiOaBaseObject oaBaseObject) {
		// 修改uecPsnjob记录
		String[] psnjobIdsModify = oaBaseObject.getPsnjobIdModify().split("-");
		String[] psnjobIdsHis = oaBaseObject.getPsnjobIdHis().split("-");
		for (int i = 0; i < psnjobIdsModify.length; i++) {
			// 保存原数据
			UecPsnjob psnjob = UecPsnjob.newInstance();
			psnjob.setPsnjobId(Long.parseLong(psnjobIdsHis[i]));
			psnjob = uecPsnjobManager.findUecPsnjobById(psnjob);
			UecPsnjob psnjobTmp = (UecPsnjob) psnjob.clone();

			// 修改原数据为审批数据
			UecPsnjob psnjobApproval = UecPsnjob.newInstance();
			psnjobApproval.setPsnjobId(Long.parseLong(psnjobIdsModify[i]));
			psnjobApproval = uecPsnjobManager.findUecPsnjobById(psnjobApproval);
			psnjobApproval.setPsnjobId(Long.parseLong(psnjobIdsHis[i]));
			psnjobApproval.updateStatusCdIs0();

			// 修改审批数据为历史数据
			psnjobTmp.setPsnjobId(Long.parseLong(psnjobIdsModify[i]));
			psnjobTmp.updateStatusCdIs1();
		}

		// 添加的uecPsnjob记录
		String psnjobIdsAdd = oaBaseObject.getPsnjobIdAdd();
		if (!StrUtil.isNullOrEmpty(psnjobIdsAdd)) {
			String[] psnjobIdAddArray = oaBaseObject.getPsnjobIdAdd()
					.split("-");
			for (String psnjobIdAdd : psnjobIdAddArray) {
				UecPsnjob psnjob = UecPsnjob.newInstance();
				psnjob.setPsnjobId(Long.valueOf(psnjobIdAdd));
				psnjob = uecPsnjobManager.findUecPsnjobById(psnjob);
				psnjob.updateStatusCdIs0();
			}
		}

	}
	/**
	 *若是待审批的记录里， 最高学历、全日制最高学历、在职最高学历、最高学位都是最高，则需要把历史数据变更N，防止数据不准确
	 * @param uecDocEdu
	 */
  public static void changeEdu(UecDocEdu uecDocEdu) {
	  if(uecDocEdu !=null) {
		  UecOutStaffInfo  uecOutStaffInfo = new UecOutStaffInfo();
		  uecOutStaffInfo.setOutStaffId(uecDocEdu.getStaffId());
		  List<UecDocEdu> uecDocEduByUecOutStaffId = uecDocEduManager.getUecDocEduByUecOutStaffId(uecOutStaffInfo);
		  for(UecDocEdu uecDocEdunew:uecDocEduByUecOutStaffId) {
			  if(uecDocEdunew.getEduId() != uecDocEdu.getEduId()) {
				  //是否最高学历
				  if("Y".equals(!StrUtil.isNullOrEmpty(uecDocEdu.getLasteducation())?uecDocEdu.getLasteducation():"")) {
					  uecDocEdunew.setLasteducation("N");
				  }
				  //是否全日制最高学历
				  if("Y".equals(!StrUtil.isNullOrEmpty(uecDocEdu.getGlbdef8())?uecDocEdu.getGlbdef8():"")) {
					  uecDocEdunew.setGlbdef8("N");
				  }
				  //是否在职最高学历
				  if("Y".equals(!StrUtil.isNullOrEmpty(uecDocEdu.getGlbdef9())?uecDocEdu.getGlbdef9():"")) {
					  uecDocEdunew.setGlbdef9("N");
				  }
				  //是否第一学历
				  if("Y".equals(!StrUtil.isNullOrEmpty(uecDocEdu.getGlbdef5())?uecDocEdu.getGlbdef5():"")) {
					  uecDocEdunew.setGlbdef5("N");
				  }
				  uecDocEdunew.updateOnly();
			  }
		  }
	  }
	  
  }
}
